package com.vue.cn.interceptor;

import com.vue.cn.common.http.StatusEnum;
import com.vue.cn.exception.MyException;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class LoginInterceptor extends HandlerInterceptorAdapter {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
        System.out.println("登录拦截器拦截了此请求：  " + request.getRequestURL());

        HttpSession session = request.getSession();
        System.err.println(session);
        Object user = session.getAttribute("user");
        System.out.println(user);
        if (user != null) {
            System.out.println("登录成功");
            return true;
        }
        System.out.println("登录失败");
        throw new MyException(StatusEnum.EEEOR_NOT_LOGIN);

    }

}
